package org.shop.controller.liveManager;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.shop.dao.JoinInfoMapper;
import org.shop.service.JoinInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LiveManagerJoinInfoController {

private static Logger logger = LogManager.getLogger(LiveManagerJoinInfoController.class);
	
	@Autowired
	private JoinInfoService joinInfoService;
	@Autowired
	private JoinInfoMapper joinInfoMapper;
	
	/**
	 * 获取参加人员信息列表
	 * @param req
	 * @return
	 */
	@RequestMapping("liveManager/getJoinInfoList")
	@ResponseBody
	public Map<String,Object> getJoinInfoList(HttpServletRequest req){
		Map<String,Object> map = new HashMap<String,Object>();
	 	String currentPage = req.getParameter("offset");
        String pageSize = req.getParameter("limit");
        String userName = req.getParameter("userName");
        String activityId = req.getParameter("activityId");
		try{
			Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("startPage", Integer.parseInt(currentPage));
            paramMap.put("pageSize", Integer.parseInt(pageSize));
            paramMap.put("userName", userName);
            paramMap.put("activityId", activityId);
            map = joinInfoService.getJoinInfoList(paramMap);
		}catch(Exception e){
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return map;
	}
	
	/**
	 * 参加人员的数量
	 * @param req
	 * @return
	 */
	@RequestMapping("liveManager/getJoinInfoCount")
	@ResponseBody
	public int getJoinInfoCount(HttpServletRequest req) {
		Map<String,Object> map = new HashMap<String,Object>();
		int num = 0;
		String activityId = req.getParameter("activityId");
		try {
			map.put("activityId", activityId);
			num = joinInfoMapper.getJoinInfoCount(map);
		}catch(Exception e) {
			num = 0;
			e.printStackTrace();
			logger.error(e.getMessage());
		}
		return num;
	}
	
	
}
